package com.foreknow.elm.test;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class LoginSevlet extends HttpServlet {
    @Override
    public void init(ServletConfig config) throws ServletException {
        //初始化方法
        //获取初始化参数
        int pageSize = Integer.parseInt(config.getInitParameter("pageSize"));
        System.out.println(pageSize);
    }

    @Override
    public void destroy() {
        System.out.println("销毁对象......");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置请求信息的字符编码（必须在使用request之前进行设置）
        req.setCharacterEncoding("utf-8");
        //使客户端浏览器并根据不同的MIME调用浏览器内不同的程序嵌入模块来处理相应的数据。
        resp.setContentType("text/html;charset=utf-8");
        //设置响应信息的字符编码（必须在创建响应输出流之前进行设置）
        resp.setCharacterEncoding("utf-8");
        PrintWriter out = resp.getWriter();
        //获取请求参数
        String username = req.getParameter("username"); //用户名
        String password = req.getParameter("password"); //密码
        //在网页中输出用户名和密码
        out.println(username);
        out.println(password);




    }
}
